<?php

/*
 +--------------------------------------------------------------------------+
 | Zephir                                                                   |
 | Copyright (c) 2013-present Zephir Team (https://zephir-lang.com/)        |
 |                                                                          |
 | This source file is subject the MIT license, that is bundled with this   |
 | package in the file LICENSE, and is available through the world-wide-web |
 | at the following url: http://zephir-lang.com/license.html                |
 +--------------------------------------------------------------------------+
 */

namespace Zephir\Compiler;

use Zephir\Exception\RuntimeException;

/**
 * Zephir\Compiler\CompilerException
 *
 * Exceptions generated by the compiler
 *
 * @package Zephir\Compiler
 */
class CompilerException extends RuntimeException
{
    /**
     * CompilerException constructor.
     *
     * @param string $message The Exception message to throw [optional].
     * @param array|null $extra Extra info [optional].
     * @param int $code The Exception code [optional].
     * @param \Throwable|\Exception $previous The previous throwable used for the exception chaining [optional].
     */
    public function __construct($message = '', $extra = null, $code = 0, $previous = null)
    {
        if (is_array($extra) && isset($extra['file'])) {
            $message .= " in " . $extra['file'] . " on line " . $extra['line'];
        }

        $this->extra = $extra;

        parent::__construct($message, $code, $previous);
    }
}
